package com.gin.kotlin.no_gay_alliance.provider.ngaphp

import com.gin.kotlin.no_gay_alliance.model.ForumEntryModel
import com.gin.nga.main.NgaApi
import com.gin.nga.response.forum.FavorForum
import java.lang.ref.WeakReference

/**
 * 收藏版面数据提供者
 */
class FavorForumProvider private constructor() : AbstractCachedDataProvider<Nothing, List<List<FavorForum>>, List<ForumEntryModel>>(
    javaType = TYPE_FACTORY.constructCollectionLikeType(List::class.java, ForumEntryModel::class.java)
) {
    override val dir = "FAVOR_FORUM"
    override fun transform(rawData: List<List<FavorForum>>) = rawData.flatten().map { ForumEntryModel(it) }
    override fun requestMethod(ngaApi: NgaApi, params: Nothing?) = ngaApi.forumApi.favorList()
    override fun obtainRelativePath(userId: Long, params: Nothing?) = "${userId}.json"

    companion object {
        private var instance: WeakReference<FavorForumProvider> = WeakReference(FavorForumProvider())
        fun getInstance(): FavorForumProvider = instance.get() ?: FavorForumProvider().also { instance = WeakReference(it) }
    }
}